home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch10 / Peano.frm (.txt) < prev    next >
Visual Basic Form  |  1999-06-08  |  3KB  |  108 lines

  1. VERSION 5.00
  2. Begin VB.Form frmPeano 
  3.    Caption         =   "Peano"
  4.    ClientHeight    =   4335
  5.    ClientLeft      =   2280
  6.    ClientTop       =   900
  7.    ClientWidth     =   5310
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   4335
  11.    ScaleWidth      =   5310
  12.    Begin VB.TextBox txtDepth 
  13.       Height          =   285
  14.       Left            =   480
  15.       MaxLength       =   3
  16.       TabIndex        =   0
  17.       Text            =   "2"
  18.       Top             =   0
  19.       Width           =   375
  20.    End
  21.    Begin VB.PictureBox picCanvas 
  22.       AutoRedraw      =   -1  'True
  23.       Height          =   4335
  24.       Left            =   960
  25.       ScaleHeight     =   285
  26.       ScaleMode       =   3  'Pixel
  27.       ScaleWidth      =   285
  28.       TabIndex        =   3
  29.       Top             =   0
  30.       Width           =   4335
  31.    End
  32.    Begin VB.CommandButton cmdGo 
  33.       Caption         =   "Go"
  34.       Default         =   -1  'True
  35.       Height          =   375
  36.       Left            =   120
  37.       TabIndex        =   1
  38.       Top             =   480
  39.       Width           =   615
  40.    End
  41.    Begin VB.Label Label1 
  42.       Caption         =   "Depth"
  43.       Height          =   255
  44.       Index           =   0
  45.       Left            =   0
  46.       TabIndex        =   2
  47.       Top             =   0
  48.       Width           =   495
  49.    End
  50. Attribute VB_Name = "frmPeano"
  51. Attribute VB_GlobalNameSpace = False
  52. Attribute VB_Creatable = False
  53. Attribute VB_PredeclaredId = True
  54. Attribute VB_Exposed = False
  55. Option Explicit
  56. ' Draw a Peano curve.
  57. Private Sub Peano(ByVal depth As Integer, ByVal dx As Single, ByVal dy As Single)
  58. Dim dx3 As Single
  59. Dim dy3 As Single
  60.     If depth > 0 Then
  61.         dx3 = dx / 3
  62.         dy3 = dy / 3
  63.         Peano depth - 1, dx3, dy3
  64.         Peano depth - 1, dy3, dx3
  65.         Peano depth - 1, dx3, dy3
  66.         Peano depth - 1, -dy3, -dx3
  67.         Peano depth - 1, -dx3, -dy3
  68.         Peano depth - 1, -dy3, -dx3
  69.         Peano depth - 1, dx3, dy3
  70.         Peano depth - 1, dy3, dx3
  71.         Peano depth - 1, dx3, dy3
  72.     Else
  73.         picCanvas.Line -Step(dx, dy)
  74.     End If
  75. End Sub
  76. Private Sub cmdGo_Click()
  77. Dim depth As Integer
  78. Dim total_length As Single
  79. Dim start_x As Single
  80. Dim start_y As Single
  81.     picCanvas.Cls
  82.     MousePointer = vbHourglass
  83.     DoEvents
  84.     ' Get the parameters.
  85.     If Not IsNumeric(txtDepth.Text) Then txtDepth.Text = "5"
  86.     depth = CInt(txtDepth.Text)
  87.     ' See how big we can make the curve.
  88.     If picCanvas.ScaleHeight < picCanvas.ScaleWidth Then
  89.         total_length = 0.9 * picCanvas.ScaleHeight
  90.     Else
  91.         total_length = 0.9 * picCanvas.ScaleWidth
  92.     End If
  93.     start_x = picCanvas.ScaleWidth / 2
  94.     start_y = (picCanvas.ScaleHeight - total_length) / 2
  95.     ' Draw the curve.
  96.     picCanvas.CurrentX = start_x
  97.     picCanvas.CurrentY = start_y
  98.     Peano depth, 0, total_length
  99.     MousePointer = vbDefault
  100. End Sub
  101. Private Sub Form_Resize()
  102. Dim wid As Single
  103.     wid = ScaleWidth - picCanvas.Left
  104.     If wid < 120 Then wid = 120
  105.     picCanvas.Move picCanvas.Left, 0, _
  106.         wid, ScaleHeight
  107. End Sub
  108.